﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.IO;

namespace del
{
    public partial class Form1 : Form
    {
        public SqlCommand Sqlcmd;
        public SqlDataReader Sqldr;
        public SqlDataAdapter Adapter;
        public SqlConnection connection;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Sqlcmd = new SqlCommand();
            Adapter = new SqlDataAdapter();

            DBConnection("SQLSERVER", "TestQ", "user", "pass");
            Sqlcmd.Connection = connection;
        }

        public bool DBConnection(string server, string db, string id, string pass)//--------------------------------------подключение к базе
        {
            bool rez = false;
            try
            {
                connection = new SqlConnection("Data Source=" + server + ";Initial Catalog=" + db + ";uid = " + id + "; pwd = " + pass);
                try
                {
                    connection.Open();
                    rez = true;
                }
                catch (SqlException se) { MessageBox.Show("ошибка подключения к базе:\n" + se.Message + "\n\n"); }
            }
            catch (Exception se) { MessageBox.Show("Ошибка DBConnection:\n" + se.Message + "\n\n"); }
            return rez;
        }

        private void toolStripButtonMenu_Click(object sender, EventArgs e)
        {
            menu dlg = new menu();
            dlg.ShowDialog();
        }

        private void toolStripButtonCostum_Click(object sender, EventArgs e)
        {
            user dlg = new user();
            dlg.ShowDialog();
        }

        private void toolStripButtonCalendar_Click(object sender, EventArgs e)
        {
            
        }

        private void toolStripButtonProduct_Click(object sender, EventArgs e)
        {

        }
    }
}
